package com.xb.p17_intentdata;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void go(View view){
        EditText editText1=findViewById(R.id.text1);
        EditText editText2=findViewById(R.id.text2);

        Intent intent=new Intent();

        //显示调用
       /*ComponentName comp=new ComponentName(this,Activity2.class);
        intent.setComponent(comp);*/

        //通过setAction来隐式调用
        intent.setAction("com.xb.p17_intentdata.Activity2");

        Bundle bundle=new Bundle();
        bundle.putString("text1",editText1.getText().toString());
        bundle.putString("text2",editText2.getText().toString());

        intent.putExtras(bundle);
        startActivity(intent);
    }

    public void go2(View view){
        EditText editText1=findViewById(R.id.text1);
        EditText editText2=findViewById(R.id.text2);

        Intent intent=new Intent();

        Bundle bundle=new Bundle();
        bundle.putString("text1",editText1.getText().toString());
        bundle.putString("text2",editText2.getText().toString());
        intent.putExtras(bundle);

        intent.setClass(this,Activity3.class);
        startActivityForResult(intent,0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==0){
            if(resultCode==2){
                Toast.makeText(this,data.getExtras().getString("result"),Toast.LENGTH_LONG).show();
            }
        }
    }
}